package com.zhiwang.planet.mvvm.viewmodel.main

import android.text.Html
import android.text.TextUtils
import android.view.View
import android.widget.LinearLayout
import androidx.databinding.ObservableBoolean
import com.zhiwang.planet.widget.ExpandableTextView

class NotificationItemViewModel constructor(var id: String, var type: String,var title:String, var content: String, var date: String, var hasRead: ObservableBoolean,
                                            var link: String?) : SetReadCallBack {

    override fun onCallBack() {
        hasRead.set(true)
    }

    var expand = false

    fun toggle(v: View) {

        if (hasRead.get().not()) {
            ConnectionViewModel.message.value = ConnectionProto(type, id, this)
        }

        if (TextUtils.isEmpty(link).not()){
            ConnectionViewModel.linkEvent.value = link
            return
        }

        ((v as LinearLayout).getChildAt(1) as ExpandableTextView).toggle(true)

        expand = !expand

    }

}

